package cn.jbolt.ai.core.chain.node.flow.ifcondition;

import cn.jbolt.util.JSONUtil;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.ArrayNode;

public class IfNodeConfig {


    /**
     * 多组条件
     * groupConditions: [
     *     {
     *         groupLink: 'and',
     *         conditions: [
     *             {
     *                 link:'and',
     *                 inputField: null,
     *                 operator: '==',
     *                 compareValue: '',
     *             }
     *         ]
     *     }
     * ],
     */
    private ArrayNode groupConditions;

    private String outputField;

    public static IfNodeConfig from(JsonNode jsonNode) {
        if (jsonNode == null) {
            return new IfNodeConfig();
        }
        return JSONUtil.toObject(jsonNode, IfNodeConfig.class);
    }


    /**
     * 获取第一个分组的条件
     * @return
     */
    public ArrayNode getFristGroupConditions() {
        if (groupConditions == null || groupConditions.size() == 0) {
            return null;
        }
        return (ArrayNode) groupConditions.get(0).get("conditions");
    }


    public ArrayNode getGroupConditions() {
        return groupConditions;
    }

    public void setGroupConditions(ArrayNode groupConditions) {
        this.groupConditions = groupConditions;
    }

    public String getOutputField() {
        return outputField;
    }

    public void setOutputField(String outputField) {
        this.outputField = outputField;
    }
}
